﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Script_Text_Editor_WPF_Edition.Support.Backend
{
    class TextSupport
    {
        /// <summary>
        /// 选定括号之间的文字
        /// </summary>
        /// <param name="strInput"></param>
        /// <returns>开始位置及长度</returns>
        public static int[] SelectTextBox(string strInput)
        {
            if (strInput.Length < 1)
                return new int[] { 0, 0 };

            int start;
            if (strInput[0] == '　')
                start = 0;
            else
                start = strInput.IndexOfAny(new char[] { '「', '『', '【' }, 0);

            int end = strInput.LastIndexOfAny(new char[] { '」', '』', '】' }, strInput.Length - 1);

            if (start == -1 && end != -1)
            {
                return new int[] { 0, end };
            }
            else if (start != -1 && end == -1)
            {
                return new int[] { start + 1, strInput.Length - start };
            }
            else if (start == -1 && end == -1)
            {
                return new int[] { 0, strInput.Length };
            }
            else
            {
                return new int[] { start + 1, end - start - 1 };
            }
        }
    }
}